From 0867b6e8df59f28fc9d35d2f7044fc26cec6d64d Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Wed, 19 Dec 2018 11:11:59 -0500 Subject: [PATCH] ApiBlock: Avoid PHP warning when partial blocks are enabled but not used If partial blocks are available but a sitewide block is being made, $params['pagerestrictions'] is null and implode() raises a warning. Since null casts to the empty array, it's easy enough to work around. Also add a test hitting this case. Change-Id: Id7e2559d7569031b7c1228adb0c0a14b3c1527c3 --- includes/api/ApiBlock.php | 2 +- tests/phpunit/includes/api/ApiBlockTest.php | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/includes/api/ApiBlock.php b/includes/api/ApiBlock.php index 8976626a57..ed3d01ce8e 100644 --- a/includes/api/ApiBlock.php +++ b/includes/api/ApiBlock.php @@ -61,7 +61,7 @@ class ApiBlock extends ApiBase { $editingRestriction = 'partial'; } - $pageRestrictions = implode( "\n", $params['pagerestrictions'] ); + $pageRestrictions = implode( "\n", (array)$params['pagerestrictions'] ); } if ( $params['userid'] !== null ) { diff --git a/tests/phpunit/includes/api/ApiBlockTest.php b/tests/phpunit/includes/api/ApiBlockTest.php index e229f0c106..feafdef7e0 100644 --- a/tests/phpunit/includes/api/ApiBlockTest.php +++ b/tests/phpunit/includes/api/ApiBlockTest.php @@ -215,6 +215,19 @@ class ApiBlockTest extends ApiTestCase { $this->doBlock( [ 'expiry' => '' ] ); } + public function testBlockWithoutRestrictions() { + $this->setMwGlobals( [ + 'wgEnablePartialBlocks' => true, + ] ); + + $this->doBlock(); + + $block = Block::newFromTarget( $this->mUser->getName() ); + + $this->assertTrue( $block->isSitewide() ); + $this->assertCount( 0, $block->getRestrictions() ); + } + public function testBlockWithRestrictions() { $this->setMwGlobals( [ 'wgEnablePartialBlocks' => true, -- 2.20.1